#include <iostream>
using namespace std;

#include <pthread.h>
#include <unistd.h>
#include <thread>
pthread_rwlock_t g_rwlock;
int g_num = 100;
//读锁
void * threadFunc1(void *arg)
{   
    // while(1)
    // {
        pthread_rwlock_rdlock(&g_rwlock);
        for(int idx = 0;idx < 10;idx++)
        {
            cout<<"threadFunc1 g_num:"<<g_num<<endl;
            sleep(1);
        }
        pthread_rwlock_unlock(&g_rwlock);
    // }
    
    pthread_exit(NULL);
}

void * threadFunc2(void *arg)
{   
    // while(1)
    // {
        pthread_rwlock_rdlock(&g_rwlock);
        for(int idx = 0;idx < 10;idx++)
        {
            cout<<"threadFunc2 g_num:"<<g_num<<endl;
            sleep(1);
        }
        pthread_rwlock_unlock(&g_rwlock);
    // }
    pthread_exit(NULL);
}

void * threadFunc3(void *arg)
{

}
int main()
{   
    //初始化锁
    pthread_rwlock_init(&g_rwlock,NULL);

    //释放读写锁
    pthread_rwlock_destroy(&g_rwlock);

    return 0;
}